/*******************************************************************************
 * Copyright (c) 2011, 2013 EclipseSource and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *    EclipseSource - initial API and implementation
 ******************************************************************************/
package it.rap.applications.contributions.manager;

import it.rap.applications.container.IContainerContribution;
import it.rap.applications.container.IContainerPage;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


public class Contributions {

  private static final List<IContainerContribution> contributions;

  static {
	  contributions = new ArrayList<IContainerContribution>();
  }
  
  public static List<IContainerContribution> getContibutions() {
    return Collections.unmodifiableList( contributions );
  }

  public static void addContribution( final String id, final String title, final Class<? extends IContainerPage> clazz )
  {
    IContainerContribution contribution = new IContainerContribution() {

      public String getId() {
        return id;
      }

      public String getTitle() {
        return title;
      }

      public IContainerPage createPage() {
        try {
          return clazz.newInstance();
        } catch( Exception exception ) {
          throw new RuntimeException( "Failed to instatiate class " + clazz.getName(), exception );
        }
      }
    };
    contributions.add( contribution );
  }

}
